﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Gapi.Search;
using ChrizNet.Infrastructure;

namespace ChrizNet.SearchService
{
    public class GoogleRESTSearch
    {
        public List<SearchData> GetResponse(String message)
        {
            string searchTerm = message;
            List<SearchData> result = new List<SearchData>();
            Gapi.Search.SearchResults searchResults;
            try
            {
                searchResults = Searcher.Search(SearchType.Web, searchTerm);
                foreach (var row in searchResults.Items)
                {
                    var data = new SearchData()
                    {
                        Content=   HttpUtility.HtmlDecode(row.Content),
                        Title = row.Title,
                        Url = row.Url
                    };
                    result.Add(data);
                }
                return result;
            }
            catch 
            {
                return result;
            }
        }
    }
}
